<?php

namespace app\common\model;

class PointReceive extends Base
{
    /**
     * 获取用户剩余积分
     * @param string $openid
     * @return WeixinIntegral|array|int|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getUserIntegralSurplus(string $openid = '')
    {
        //获取当前
        $integral = $this->field('sum(number) as integral')
            ->where('openid', $openid)
            ->find();
        return $integral['integral'] ?? 0;
    }
}